From f1b3a3b311cb213d806f50bad9518885a619e77c Mon Sep 17 00:00:00 2001 From: "cl349@firebug.cl.cam.ac.uk" Date: Tue, 26 Jul 2005 17:16:55 +0000 Subject: [PATCH] Do not use device_find: crashes for some reason Signed-off-by: Rusty Russel Signed-off-by: Christian Limpach --- .../drivers/xen/xenbus/xenbus_probe.c | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c index b703bcce7d..f6f29bfaf0 100644 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c @@ -113,6 +113,33 @@ void xenbus_unregister_driver(struct xenbus_driver *drv) driver_unregister(&drv->driver); } +struct xb_find_info +{ + struct xenbus_device *dev; + const char *busid; +}; + +static int cmp_dev(struct device *dev, void *data) +{ + struct xb_find_info *info = data; + + if (streq(dev->bus_id, info->busid)) { + info->dev = container_of(get_device(dev), + struct xenbus_device, dev); + return 1; + } + return 0; +} + +/* FIXME: device_find seems to be broken. --RR */ +struct xenbus_device *xenbus_device_find(const char *busid) +{ + struct xb_find_info info = { .dev = NULL, .busid = busid }; + + bus_for_each_dev(&xenbus_type, NULL, &info, cmp_dev); + return info.dev; +} + /* devices// */ static int xenbus_probe_device(const char *dirpath, const char *devicetype, const char *name) @@ -200,7 +227,7 @@ static void dev_changed(struct xenbus_watch *watch, const char *node) char busid[BUS_ID_SIZE]; unsigned int typelen, idlen; int exists; - struct device *dev; + struct xenbus_device *dev; char *type; /* Node is of form device//[/...] */ @@ -225,17 +252,19 @@ static void dev_changed(struct xenbus_watch *watch, const char *node) exists = xenbus_exists("device", busid); busid[typelen] = '-'; - dev = device_find(busid, &xenbus_type); + dev = xenbus_device_find(busid); if (dev && !exists) { printk("xenbus: Unregistering device %s\n", busid); /* FIXME: free? */ - device_unregister(dev); + device_unregister(&dev->dev); } if (!dev && exists) { printk("xenbus: Adding device %s\n", busid); busid[typelen] = '\0'; xenbus_probe_device("device", busid, busid+typelen+1); } + if (dev) + put_device(&dev->dev); } /* We watch for devices appearing and vanishing. */ -- 2.30.2